package com.activemq;

import cn.hutool.core.util.IdUtil;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQTextMessage;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.jms.JmsProperties;

import javax.jms.*;

/**
 * TextMessage：textMessage和MapMessage涵盖95%
 * MapMessage：
 * BytesMessage：
 * StreamMessage：
 * ObjectMessage：序列化
 */
@Slf4j
public class MsgProp {
    public static void main(String[] args) throws Exception {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(MqHelloWorld.URL);
        Connection connection = factory.createConnection();
        connection.start();
        Session session = connection.createSession(false, JmsProperties.AcknowledgeMode.AUTO.getMode());
        Queue queue = session.createQueue(MqHelloWorld.QUEUE);
        MessageProducer producer = session.createProducer(queue);
        TextMessage message = session.createTextMessage("111测试");
        message.setJMSMessageID(IdUtil.getSnowflakeNextIdStr());
        //持久化
        message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
        //优先级
        message.setJMSExpiration(0L);
        //
        message.setJMSPriority(Message.DEFAULT_PRIORITY);
        //发送
        producer.send(message);
        producer.close();
        session.close();
        connection.close();
    }

}

@Slf4j
class TestId {
    @Test
    void test() {
        log.error(IdUtil.getSnowflakeNextIdStr());
        HttpUtil.post("", "");
    }
}